if (!window.Func)
	window.Func = {};

/**
 * 组织机构
 */
Func.Org = {
	
	/**
	 * 通过ViewBean的id弹出一个编辑窗口
	 * 
	 * @param compId 		ViewBean ID
	 */
	openOrgEdit : function(compId){
		var sel = SinoPortal.PageView.dataView.getSelected(compId+"_right_main");
		if(sel.length==0){
			SinoPortal.Confirm.show("error",null,"请先选择一个待编辑的部门或者用户。");
			return;
		}
		var id = jQuery(sel[0]).attr('exdata');
		var params = id.split(",");
		if(params[1] == 'org'){
			Func.Org.openEditDir('org-manage-scene','org-add-and-edit','update',params[0],params[2],'编辑部门['+params[3]+']');
		}else if(params[1] == 'user'){
			Func.Org.openEditDir('org-manage-scene','user-add-and-edit','update',params[0],params[2],'编辑用户['+params[3]+']');
		}
	},
	
	openEditDir : function(sceneId,layoutId,type,compId,nodeId,displayName){
		SinoPortal.View.createWin(sceneId,layoutId,compId,{selectedId:nodeId,type:type,displayName:displayName});
	},

	deleteOrg : function(compId){
		var sel = SinoPortal.PageView.dataView.getSelected(compId+"_right_main");
		if(sel.length==0){
			SinoPortal.Confirm.show("error",null,"请先选择一个要删除的部门或者用户。");
			return;
		}else{
			var id = jQuery(sel[0]).attr('exdata');
			var params = id.split(",");
			if(params[1] == 'org'){
				SinoPortal.Confirm.showConfirm('确认','是否删除部门【'+params[3]+'】？',compId+'_deleteOrg("'+compId+','+params[2]+','+params[1]+'")');
			}else if(params[1] == 'user'){
				SinoPortal.Confirm.showConfirm('确认','是否删除用户【'+params[3]+'】？',compId+'_deleteOrg("'+compId+','+params[2]+','+params[1]+',user")');
			}
			
		}
	},
	
	rePwd : function(compId){
		var sel = SinoPortal.PageView.dataView.getSelected(compId+"_right_main");
		if(sel.length==0){
			SinoPortal.Confirm.show("error",null,"请选择一个需要重置密码的用户。");
			return;
		}else{
			var id = sel[0].id;
			var params = id.split(",");
			if(params[1] == 'user'){
				SinoPortal.Confirm.showConfirm('确认','确定要重置【'+params[3]+'】的密码吗？',compId+'_deleteOrg("'+compId+','+params[2]+','+params[1]+',rePwd")');
			}else{
				SinoPortal.Confirm.show("error",null,"请选择一个需要重置密码的用户。");
				return;
			}
		}
	},
	
	openUserRole : function(compId){
		var sel = SinoPortal.PageView.dataView.getSelected(compId+"_right_main");
		//console.log(sel);
		if(sel.length==0){
			SinoPortal.Confirm.show("error",null,"请先选择一个要分配角色的用户。");
			return;
		}else{
			var id = sel[0].id;
			var params = id.split(",");
			//console.log(params);
			if(params[1] == 'user'){
				Func.Org.openEditDir('org-manage-scene','user-group-role','group',params[0],params[2],'给【'+params[3]+'】分配角色');
			}else{
				SinoPortal.Confirm.show("error",null,"请先选择一个要分配角色的用户。");
				return;
			}
		}
	},
	
	/**
	 * 调动部门
	 */
	removeOrg : function(compId){
		var sel = SinoPortal.PageView.dataView.getSelected(compId+"_right_main");
		//console.log(sel);
		if(sel.length==0){
			SinoPortal.Confirm.show("error",null,"请先选择一个要调动部门的用户。");
			return;
		}else{
			var id = sel[0].id;
			var params = id.split(",");
			//console.log(params);
			if(params[1] == 'user'){
				Func.Org.openEditDir('org-manage-scene','user-remove-org','removeOrg',params[0],params[2],'给【'+params[3]+'】调动部门');
			}else{
				SinoPortal.Confirm.show("error",null,"请先选择一个要调动部门的用户。");
				return;
			}
		}
	},
	
	chooseUser:function(viewBeanId){
		var sel = SinoPortal.PageView.dataView.getSelected(viewBeanId+"_cru_main");
		//console.log(sel);
		if(sel.length==0){
			SinoPortal.Confirm.show("error",null,"请先选择一个要分配角色的用户。");
			return;
		}else{
			var id = sel[0].id;
			alert(id);
			//var params = id.split(",");
			//console.log(params);
			if(id!='undefine'&&id!=''){
				alert("99999990000000");
				alert(viewBeanId);
				eval(viewBeanId+"_submit('"+id+","+viewBeanId+"')");
			}else{
				SinoPortal.Confirm.show("error",null,"请先选择一个要分配角色的用户。");
				return;
			}
		}
	}
	
	
};